#!/usr/bin/env python3
import requests

OUTPUT_PATH = 'debug_last_response.html'

def check_html_response():
    try:
        # 发送POST请求
        response = requests.post('http://127.0.0.1:5000', data={'coin': 'BTC'})
        content = response.text

        # 将完整响应写入文件，便于人工排查
        with open(OUTPUT_PATH, 'w', encoding='utf-8') as f:
            f.write(content)
        print(f'已将响应保存到 {OUTPUT_PATH}')
        
        print('=== 检查模板标记 ===')
        marker = 'TEMPLATE_MARKER: 2025-09-11-TA-FIX'
        if marker in content:
            print('找到了模板标记')
        else:
            print('未找到模板标记')
        
        print('=== 检查HTML响应中的已移除指标 ===')
        
        # 搜索关键词
        keywords = ['stochastic', 'williams', 'cci', 'momentum']
        found_lines = []
        
        lines = content.split('\n')
        for i, line in enumerate(lines):
            line_lower = line.lower()
            for keyword in keywords:
                if keyword in line_lower:
                    found_lines.append((i+1, line.strip(), keyword))
        
        if found_lines:
            print(f"发现 {len(found_lines)} 行包含已移除指标:")
            for line_num, line_content, keyword in found_lines:
                print(f"第{line_num}行 [{keyword}]: {line_content}")
        else:
            print("未发现已移除指标")
        
        # 同时检查具体的指标值
        specific_values = ['22.88', '77.12', '48.71', '98.31']
        print('\n=== 检查具体指标值 ===')
        for value in specific_values:
            if value in content:
                print(f"发现值 {value}")
                # 找到包含这个值的行
                for i, line in enumerate(lines):
                    if value in line:
                        print(f"  第{i+1}行: {line.strip()}")
        
        # 打印响应前若干行用于确认模板来源
        print('\n=== 响应前40行预览 ===')
        for i, line in enumerate(lines[:40]):
            print(f"{i+1:>3}: {line}")
        
    except Exception as e:
        print(f"检查HTML响应时出错: {e}")

if __name__ == '__main__':
    check_html_response()